﻿using JV.Com.Internals;
using JV.Com.ViewModels;
using Microsoft.Practices.Prism.StoreApps;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238

namespace JV.Com.Views
{
    /// <summary>
    /// Une page vide peut être utilisée seule ou constituer une page de destination au sein d'un frame.
    /// </summary>
    public sealed partial class FolderPage : PageBase
    {
        private FolderPageViewModel m_context;
        public FolderPage()
        {
            this.InitializeComponent();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            this.DataContextChanged += (s, args) =>
            {
                m_context = (FolderPageViewModel)args.NewValue;
                PrepareSubNavigationService();
            };
        }

        private void PrepareSubNavigationService()
        {
            var frameFacade = new FrameFacadeAdapter(FolderFrame);
            var sessionStateService = new SessionStateService();
            var navigationService = new FrameNavigationService(frameFacade, (str) => typeof(DetailFolderPage), sessionStateService);
            ViewModelLocator.Register(typeof(DetailFolderPage).ToString(), () => new ViewModels.DetailFolderPageViewModel(m_context, navigationService));
            m_context.FolderNavigationService = navigationService;
        }
    }
}
